package ru.amse.baltijsky.javascheme.importer.test;

import ru.amse.baltijsky.javascheme.importer.IImporter;
import static ru.amse.baltijsky.javascheme.importer.test.TestImporterTools.createNodeDeeperLevel;
import static ru.amse.baltijsky.javascheme.importer.test.TestImporterTools.createNodeSameLevel;
import static ru.amse.baltijsky.javascheme.tree.NodeType.*;
import ru.amse.baltijsky.javascheme.tree.SchemaNode;
import ru.amse.baltijsky.javascheme.tree.SchemaTree;
import ru.amse.baltijsky.javascheme.tree.TranslationUnitNode;

import java.io.IOException;
import java.io.Reader;

/**
 * A dumb importer for importing Java code such as found in {@code MyTest3.java}.
 */
public class SampleImporterTest3 implements IImporter {
    /**
     * Builds an artificial schema tree for the following code:
     * public class MyTest3 {
     * public static void main(String[] args) {
     * int a = 5;
     * int b = a;
     * if(a == 5) {
     * a = 4;
     * a = 3;
     * } else if (a == 4) {
     * if(b == 4) {
     * b = 0;
     * } else {
     * b = 1;
     * }
     * a = 2;
     * } else {
     * a = 0;
     * }
     * System.out.println(a);
     * }
     * }
     *
     * @param in         ignored
     * @param className
     * @param methodName
     * @return root of the tree
     * @throws IOException if an input error occurred while parsing the given source code
     */
    public SchemaTree loadTree(Reader in, String className, String methodName) throws IOException {
        // the root of the resulting tree
        SchemaNode root = new TranslationUnitNode();
        // the node that is being constructed: cur
        SchemaNode cur = createNodeDeeperLevel(CLASS, root, new String[]{"Dumb"});
        cur = createNodeDeeperLevel(METHOD, cur, new String[]{"void f()"});

        // the code
        cur = createNodeDeeperLevel(ACTION, cur, new String[]{"int a = 5"});
        cur = createNodeSameLevel(IF, cur, new String[]{""});

        return new SchemaTree(root);
    }

    public SchemaTree[] loadTrees(Reader in) throws IOException {
        return new SchemaTree[0];
    }

    public String[] getClasses(Reader in) throws IOException {
        return new String[0];
    }

    public String[] getMethods(Reader in, String className) throws IOException {
        return new String[0];
    }
}
